package com.zxl.app.controller.Information;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.zxl.app.service.InformationService;
import com.zxl.common.Page;
import com.zxl.common.Result;
import com.zxl.common.constant.CommonStatusConstant;
import com.zxl.common.constant.DeleteStatusConstant;
import com.zxl.common.model.pojo.SysInformation;
import com.zxl.common.model.pojo.SysInformationGroup;
import com.zxl.common.model.query.information.InformationQuery;
import com.zxl.common.model.vo.information.InformationDetailVo;
import com.zxl.common.model.vo.information.InformationVo;
import com.zxl.common.service.SysInformationGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxw
 * @since 2023-04-24
 */
@Api(tags = "新闻模块")
@RestController
@RequestMapping("/app/information")
public class InformationController {
    @Resource
    private InformationService informationService;
    @Resource
    private SysInformationGroupService sysInformationGroupService;

    @ApiOperation("新闻分类标签")
    @GetMapping("/label")
    public Result<List<SysInformationGroup>> label(){
        List<SysInformationGroup> list = sysInformationGroupService.list(new QueryWrapper<SysInformationGroup>()
                .eq("status", CommonStatusConstant.ADOPT.getCode())
                .eq("delete_status", DeleteStatusConstant.NOT_DELETE.getCode())
                .orderByDesc("create_time"));
        return new Result(list);
    }

    @ApiOperation("新闻列表")
    @GetMapping("/select")
    public Result<Page<InformationVo>> selectInformation(InformationQuery query){
        List<InformationVo> list = informationService.selectInformation(query);
        Page<InformationVo> page = Page.pageInfoConvert(new PageInfo(list));
        return new Result(page);
    }

    @ApiOperation("新闻详情")
    @GetMapping("/details")
    public Result details(@ApiParam(value = "新闻id", required = true)@RequestParam("id") Integer id){
        InformationDetailVo details = informationService.details(id);
        return new Result(details);
    }



}
